package com.emergency.evaluate.dao;

import com.emergency.evaluate.domain.Autoscore;
import com.emergency.evaluate.domain.Extract;
import com.emergency.evaluate.domain.Score;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.beans.Transient;
import java.util.List;

/**
 * Created by Administrator on 2020/3/12.
 */
public interface AutoscoreDao extends JpaRepository<Autoscore, String>, JpaSpecificationExecutor<Autoscore> {
   //根据ID查询自动评分表
    @Query("SELECT A FROM  Autoscore  A WHERE  A.id=:id")
    Autoscore  findAllById(@Param ( "id" ) long id);
    //根据评分表id删除对应的分数表
    @Modifying
    @Query(value = "delete FROM Autoscore WHERE auto.id =:autoId ")
    void deleteAllByAutoId(@Param ( "autoId" ) Long autoId);
    //根据想定ID对应的评分表删除对应的分数表
    @Modifying
    @Query(value = "delete FROM Auto WHERE scenar.id =:scenarId ")
    void deleteByAuto(@Param ( "scenarId" ) Long scenarId);

    //根据评分表编号ID 获取对应的分数表
    @Query(value = "SELECT s FROM Autoscore s WHERE auto.id =:autoId")
    List<Autoscore> findAllByAuto(@Param ( "autoId" ) Long autoId);
    //根据提取指标ID删除相关分数
    @Modifying
    @Query(value = "delete FROM Autoscore  WHERE extract.id =:extractId ")
    void deleteByExtract(@Param ( "extractId" ) Long extractId);

}
